package com.feng.rabbitmq.seven;

import com.feng.rabbitmq.utiils.RabbitMQUtils;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;

/**
 * 生产者
 */
public class EmitLogTopic {

    //交换机的名称
    public static final String EXCHANGE_NAME = "topic_logs";

    //发送消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        Map<String,String> bindingKeyMap = new HashMap<>();
        bindingKeyMap. put("quick. orange.rabbit","被队列Q1Q2接收到");
        bindingKeyMap. put("lazy.orange.elephant","被队列Q1Q2接收到");
        bindingKeyMap. put(" quick.orange.fox","被队列Q1接收到");
        bindingKeyMap. put("1azy. brown.fox","被队列Q2接收到");
        bindingKeyMap. put("lazy.pink.rabbit","虽然满足两个绑定但只被队列Q2接收一次");
        bindingKeyMap. put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到会被丢弃");
        bindingKeyMap. put("quick.orange.male.rabbit","是四个单词不匹配任何绑定会被丢弃");
        bindingKeyMap.put(" lazy.orange.male.rabbit","是四个单词但匹配Q2");

        for (Map.Entry<String ,String> bindingKeyEntry:bindingKeyMap.entrySet()) {
            String key = bindingKeyEntry.getKey();
            String entryValue = bindingKeyEntry.getValue();
            channel.basicPublish(EXCHANGE_NAME,key,null,entryValue.getBytes());
            System.out.println("生产者发出消息："+entryValue);
        };
    }
}
